package ch.zbw.pra.sysventory.presentation.panels;

import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.VerticalLayout;

/**
 * Painted das ArchivePanel
 * 
 * @author Ralph Koster
 */

public class ArchivePanel extends VerticalLayout implements TabSheet.SelectedTabChangeListener {

	private static final long serialVersionUID = 7464991294980647339L;
	private TabSheet tabsheet;
	private HorizontalLayout titlePanel;
	private ScanversionArchivePanel scanversionPanel;
	private ComputersArchivePanel computersPanel;
	private OperatingSystemsArchivePanel operatingSystemPanel;
	private ProcessorsArchivePanel processorPanel;
	private PrintersArchivePanel printersPanel;
	private NicsArchivePanel nicPanel;
	private SoftwaresArchivePanel softwarePanel;
	private SearchPanel searchPanel;
	
	public ArchivePanel() {		
		this.titlePanel = new HorizontalLayout();
		
		this.setStyleName("archive-panel");
		this.setWidth(100, Sizeable.UNITS_PERCENTAGE);
		
		paintTitlePanel();
		
		this.tabsheet = new TabSheet();
		this.scanversionPanel = new ScanversionArchivePanel();
		this.computersPanel = new ComputersArchivePanel();
		this.operatingSystemPanel = new OperatingSystemsArchivePanel();
		this.processorPanel = new ProcessorsArchivePanel();
		this.printersPanel = new PrintersArchivePanel();
		this.nicPanel = new NicsArchivePanel();
		this.softwarePanel = new SoftwaresArchivePanel();
		this.searchPanel = new SearchPanel();
		
		paint();
	}
	
	private void paintTitlePanel() {
		titlePanel.setWidth(100, Sizeable.UNITS_PERCENTAGE);
		titlePanel.setSpacing(true);
		titlePanel.addStyleName("titlePanel");
        
        Label title = new Label("Sysventory Hard- und Software Inventarisierung - Archiv");
        title.setSizeUndefined();
        title.addStyleName("h1");
        
        titlePanel.addComponent(title);
        titlePanel.setComponentAlignment(title, Alignment.MIDDLE_CENTER);
        titlePanel.setExpandRatio(title, 1);
        
        this.addComponent(titlePanel);
	}
	
	private void paint() {
		this.setWidth(100, Sizeable.UNITS_PERCENTAGE);
		this.setHeight(100, Sizeable.UNITS_PERCENTAGE);
		this.addStyleName("archive-panel");
		
		tabsheet.setStyleName("tabsheet");
		tabsheet.addTab(scanversionPanel);
		tabsheet.addTab(computersPanel);
		tabsheet.addTab(operatingSystemPanel);
		tabsheet.addTab(processorPanel);
		tabsheet.addTab(printersPanel);
		tabsheet.addTab(nicPanel);
		tabsheet.addTab(softwarePanel);
		tabsheet.addTab(searchPanel);

		this.addComponent(tabsheet);	
	}

	@Override
	public void selectedTabChange(SelectedTabChangeEvent event) {
		TabSheet source = (TabSheet) event.getSource();
        if (source == tabsheet) {
            if (source.getSelectedTab() == computersPanel) {
            	computersPanel.loadComputers();
            }
        }
	}

	public void updateGUI() {
		scanversionPanel.updateScanversionArchivePanel();
		computersPanel.updateComputersArchivePanel();
		operatingSystemPanel.updateOperatingSystemArchivePanel();
		processorPanel.updateProcessorArchivePanel();
		printersPanel.updatePrintersArchivePanel();
		nicPanel.updateNicArchivePanel();
		softwarePanel.updateSoftwareArchivePanel();
	}
}
